home *** CD-ROM | disk | FTP | other *** search
- #ifndef _TIMER_H_
- #define _TIMER_H_
-
- /*
- * $RCSfile: timer.h,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:46 $
- */
-
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- /*
- * similar to <sys/callout.h> but uses our list functions
- */
- typedef struct timeval SELECTTIME;
- typedef long TIME; /* the type of timeval.tv_sec from <time.h> */
- typedef void *TIMERARG;
- typedef void (*TIMERFUNC)( TIMERARG );
-
- class Clock {
- private:
- SELECTTIME timeOfLastTick;
-
- protected:
- void printStats();
- void clearStats();
- #ifdef DEBUG
- void dump( );
- #endif DEBUG
-
- public:
- TIME LastSleepTime();
- TIME Elapsed(BOOL=FALSE);
- #define Reset Elapsed(TRUE)
- };
-
- class Timer : public Clock {
-
- private:
- LIST calloutList; /* waiting to expire */
- int ncallout; /* length of calloutList */
-
- LIST expiredList; /* expired - need to be called */
- int nexpired;
-
- LIST freeList;
- int nfree; /* length of free list */
-
- int nticks, nstarted, nremoved, ncalled, nnotfound; /* clearable stats */
- int highwaterUsed;
-
- public:
- void Init( int );
- TIME Tick(BOOL /* force resetting the clock */,
- BOOL /* check for expired timers */);
- void PrintStats();
- void ClearStats();
- void Start(TIME, TIMERFUNC, TIMERARG); /* to start a timer */
- BOOL Remove(TIMERFUNC, TIMERARG); /* untimeout() -- kill a timer */
-
- #ifdef DEBUG
- void Dump( int, char * );
- #endif DEBUG
- };
-
- extern "C" int gettimeofday(struct timeval*, struct timezone*);
-
- extern Timer ServerTimer;
-
- #define MAX_TIMERS 100
-
- #endif _TIMER_H_
-